package com.e3.basdoc.currency.client;

import com.e3.basdoc.currency.model.CurrencyModel;
import com.e3.template.tgf.TGFEditorDialog;
import com.e3.template.tgf.TGFSimpleFormPanel;
import com.e3.web.core.client.GwtAsyncCallback;

public class CurrencyEditorDialog extends TGFEditorDialog<CurrencyModel> {
	
	private CurrencyRPCServiceAsync service = CurrencyRPCService.Util.getInstance();

	@Override
	public String checkOnSave(CurrencyModel model) {
		String code = model.getCode();
		String name = model.getName();
		String sign = model.getSign();
		
		StringBuffer msgs = new StringBuffer();
		if (code == null || code.trim().length() == 0) {
			msgs.append(CurrencyFieldsConstant.INSTANCE.currency_code()+",");
		}
		
		if (name == null || name.trim().length() == 0) {
			msgs.append(CurrencyFieldsConstant.INSTANCE.currency_name()+",");
		}
		
		if (sign == null || sign.trim().length() == 0) {
			msgs.append(CurrencyFieldsConstant.INSTANCE.currency_sign()+",");
		}
		
		String s  = null;
		if(msgs.length()>0){
			s = msgs.substring(0,msgs.length()-1);
		}
		if(s != null){
			return CurrencyMessages.INSTANCE.msg_notnull(s);
		}
		return null;
	}

	@Override
	public TGFSimpleFormPanel<CurrencyModel> createFormPanel() {
		return new CurrencyFormPanel();
	}

	@Override
	public void executeNewService(final CurrencyModel model, GwtAsyncCallback<CurrencyModel> callback) {
		service.newCurrency(model, callback);
	}

	@Override
	public void executeModifyService(final CurrencyModel model, GwtAsyncCallback<CurrencyModel> callback) {
		service.modifyCurrency(model, callback);
	}

	@Override
	public String[] getNotNullFieldNames() {
		return CurrencyHelper.INSTANCE.getNotNullFieldNames();
	}

}
